package com.hwadee.ems.controller;

import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.core.metadata.IPage;

import com.hwadee.ems.domain.dto.Result;
import com.hwadee.ems.domain.dto.PageQuery;
import com.hwadee.ems.domain.vo.CourseVO;
import com.hwadee.ems.domain.po.TrainingProgramCourse;
import com.hwadee.ems.service.ITrainingProgramCourseService;

/**
 * <p>
 * 人才培养方案课程 前端控制器
 * </p>
 *
 * @author EnosElinsa
 * @since 2024/06/21
 */
@Slf4j
@RestController
@RequestMapping("/training_program_course")
public class TrainingProgramCourseController {

    @Resource
    private ITrainingProgramCourseService trainingProgramCourseService;

    @PostMapping
    public Result<Long> save(@RequestBody TrainingProgramCourse trainingProgramCourse) {
        log.info("save trainingProgramCourse: " + trainingProgramCourse);
        return trainingProgramCourseService.saveWithCourseCountIncrement(trainingProgramCourse);
    }

    @DeleteMapping
    public Result<Void> removeById(@RequestBody TrainingProgramCourse trainingProgramCourse) {
        log.info("removeById trainingProgramCourse: " + trainingProgramCourse);
        return trainingProgramCourseService.removeByIdWithCourseCountDecrement(trainingProgramCourse);
    }

    @GetMapping("page_by_training_program_id")
    public Result<IPage<CourseVO>> pageByTrainingProgramId(
        PageQuery pageQuery,
        @RequestParam Long trainingProgramId, 
        @RequestParam(required = false) Long category,
        @RequestParam(required = false) Long semesterId,
        @RequestParam(required = false) Long selectionMethod,
        @RequestParam(required = false) Long assessmentMethod
    ) {
        return trainingProgramCourseService.pageByTrainingProgramId(
            pageQuery,
            trainingProgramId, 
            category,
            semesterId,
            selectionMethod,
            assessmentMethod
        );
    }

}
